<!-- 特殊布局的form表单处理,如: Select 多选 -->
<template>
    <el-dialog :visible.sync="dialogVisible" class="editDialogClass">
        <el-form :label-position="'right'" label-width="120px">
            <div v-for="(item, index) in forms" :key="index">
                <el-form-item v-if="item.show" :disabled="item.disable" :label="item.title">
                    <el-input v-if="!item.type||item.type=='text'" :disabled="item.disable" v-model="item.value" />
                    <el-color-picker v-if="item.show&&item.type&&item.type=='color'" :disabled="item.disable"
                        v-model="item.value"></el-color-picker>
                    <el-select filterable remote :remote-method="remoteMethod" :loading="loading"
                        v-if="item.show&&item.type&&item.type=='select'" :disabled="item.disable"
                        :multiple="item.isMultiplay" v-model="item.selectValue" @change="typeChanged" clearable
                        placeholder="请选择">
                        <el-option v-for="subItem in item.selectList" :key="subItem.value" :label="subItem.value"
                            :value="subItem.key" />
                    </el-select>
                </el-form-item>
            </div>
            <el-form-item>
                <el-button @click="dialogVisible=false">取消</el-button>
                <el-button v-if="isEdit" type="primary" @click="submitForm()">保存</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script lang="ts">
import Vue from 'vue'
import { FormDataUtils, IFormCommonMultData } from './data/ICommon';

export default Vue.extend({
    props: ["filterName"],
    data() {
        return {
            forms: new Array<IFormCommonMultData>(),
            options: new Array<IFormCommonMultData>(),
            dialogVisible: false,
            isEdit: true,
            loading: false,
        }
    },
    mounted() {

    },
    methods: {
        remoteMethod(query: any) {
            console.error(query);
            if (query !== '') {
                this.forms.forEach(item => {
                    item.selectList = item.srcList ? item.srcList.filter(value => {
                        return value.value.indexOf(query) > -1
                    }) : []
                })
            } else {
                this.forms.forEach(item => {
                    item.selectList = item.srcList
                })
            }
        },
        submitForm() {
            this.dialogVisible = false
            console.error(this.forms)
            let obj: any = FormDataUtils.getFormMultiplayObject(this.forms)
            console.error(obj);
            this.$emit("sendUpdate", obj)
        },
        showForm(data: Array<IFormCommonMultData>, isEdit: boolean) {
            this.options = data;
            this.forms = data
            this.isEdit = isEdit
            console.error(data)
            this.dialogVisible = true;
        },
        typeChanged(v: any) {
            console.error("选择:", v)
        },
    }
})
</script>